//
//  AlertShowView.m
//  sellHouse
//
//  Created by 李 佳伟 on 2018/11/21.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "AlertShowView.h"
#import "JTCSM.h"

static AlertShowView *single = nil;
static CGFloat backViewHeight = 200;
@interface AlertShowView ()<UITextFieldDelegate>
{
    UITextField *textfield;
    NSString *textfieldValue;
}

@end

@implementation AlertShowView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (AlertShowView *)shareSingle
{
    
    @synchronized(self){
        if(single == nil){
            single =[ [AlertShowView alloc] init];
        }
        
    }
    return single;
}

- (instancetype)init{
    self = [super init];
    if (self) {
        textfieldValue = @"";
        self.frame = CGRectMake(0, 0, KSCREENWidth, KSCREENHeight);
        self.hidden = YES;
        self.userInteractionEnabled = YES;
        self.backgroundColor = RGBACOLOR(0, 0, 0, 0.3);
        CGFloat space = 30;
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(space, (KSCREENHeight-backViewHeight)/2-60, KSCREENWidth-space*2, backViewHeight)];
        [df layerWithView:backView radius:4 width:0 color:nil];
        backView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backView];
        
        UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(0, 0, backView.frame.size.width, 80) text:@"修改姓名" font:16 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        [backView addSubview:titleLabel];
        
        textfield = [UITextField initWithframe:CGRectMake(space, KVIEW_Y(titleLabel), backView.frame.size.width-2*space, 45) backgrandColor:[UIColor whiteColor] placeholder:@"请输入姓名" textAlignment:NSTextAlignmentLeft font:15 texcolor:RGBACOLOR(189, 189, 189, 1)];
        [df layerWithView:textfield radius:0 width:1 color:RGBACOLOR(241, 241, 241, 1)];
        [backView addSubview:textfield];
        textfield.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 6, 0)];
        //设置显示模式为永远显示(默认不显示)
        textfield.leftViewMode = UITextFieldViewModeAlways;
         [textfield addTarget:self action:@selector(textField1TextChange:) forControlEvents:UIControlEventEditingChanged];
        
        CGFloat buttonHeight = 50;
        UIButton *cancleButton = [[UIButton alloc]initWithFrame:CGRectMake(0, backViewHeight-buttonHeight, backView.frame.size.width/2, buttonHeight)];
        [cancleButton setTitleColor:RGBACOLOR(89, 89, 89, 1) forState:UIControlStateNormal];
        [cancleButton setBackgroundColor:[UIColor whiteColor]];
        [cancleButton setTitle:@"取消" forState:UIControlStateNormal];
        [cancleButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
        [cancleButton addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:cancleButton];
        [df lineViewWithHeightofTop:0 superView:cancleButton spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
        
        
        UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        sureButton.frame = CGRectMake(backView.frame.size.width/2, backViewHeight-buttonHeight, backView.frame.size.width/2, buttonHeight);
        [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [sureButton setBackgroundColor:RGBACOLOR(15,166,232,1)];
        [sureButton setTitle:@"提交" forState:UIControlStateNormal];
        [sureButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
        [backView addSubview:sureButton];
        [sureButton addTarget:self action:@selector(tijiao) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)show{
    self.hidden = NO;
}
-(void)hidden{
    textfield.text=@"";
    textfieldValue = @"";
    [self endEditing:YES];
    self.hidden = YES;
}
- (void)tijiao{
    [self.delegate gotoTiJiaoWithChangeName:textfieldValue];
    
}
- (void)textField1TextChange:(UITextField *)textfield{
    textfieldValue = textfield.text;
}

@end
